package cn.js.sangu.unitStore.utils;

import cn.js.sangu.unitStore.common.exception.ServiceException;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * 说明：下载工具
 * 作者：linshuo
 * 日期：2024/12/10 8:43
 */
public class DownLoadUtils {

    public static byte[] InputStream2byte(InputStream inputStream) {
        byte[] buffer;
        try (InputStream fis = inputStream; ByteArrayOutputStream bos = new ByteArrayOutputStream()){
            byte[] b = new byte[1024];
            int n;
            while ((n = fis.read(b)) != -1) bos.write(b, 0, n);
            buffer = bos.toByteArray();
        }catch (Exception e){
            throw new ServiceException("下载工具类发生异常");
        }
        return buffer;
    }
}
